package com.woniuxy.controller;


import com.woniuxy.controller.form.CreateTopicForm;
import com.woniuxy.controller.info.Result;
import com.woniuxy.service.AnswerService;
import com.woniuxy.service.TopicService;
import com.woniuxy.util.exception.ParameterException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeoutException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Kevin Martin
 * @since 2022-03-19
 */
@RestController
@RequestMapping("/topic")
public class TopicController {
    @Resource
    private AnswerService answerService;

    @PostMapping("creatTopic")
    public Result<?> creatTopic(@RequestBody @Validated CreateTopicForm createTopicForm, BindingResult bindingResult) throws TimeoutException {
        if(bindingResult.hasErrors()||createTopicForm.getAnswers().size()==0){
            throw new ParameterException();
        }

        return answerService.creatTopic(createTopicForm);
    }



}

